﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="addchoice.aspx.cs" Inherits="OnlineTestUI.BackManager.addchoice" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>新增填空题</title>
    <script type="text/javascript" src="/Scripts/pagescript.js"></script>
    <script type="text/javascript" src="/Scripts/jquery-1.10.2.js"></script>
    <script type="text/javascript">
        /* 
        用途：检查输入字符串是否为空或者全部都是空格 
        输入：str 
        返回： 
        如果全是空返回true,否则返回false 
        */
        function isNull(str) {
            if (str == "") return true;
            var regu = "^[ ]+$";
            var re = new RegExp(regu);
            return re.test(str);
        }
        function PropertyAdd() {
            var Property = document.getElementById("txtProperty").value;

            if (Property == "") {
                alert('选项不能为空！');
                document.getElementById("txtProperty").focus();
                return;
            }

            var strValue = Property + "|" + $('#selProperty option').length;
            $("#selProperty").append("<option value=" + escape(strValue) + ">" + Property + "</option>");
            document.getElementById("txtProperty").value = "";

        }
        function CheckInput() {

            if ($('#selProperty option').length > 0) {
                for (var i = 0; i < $('#selProperty option').length; i++) {
                    document.getElementById('hidProperty').value += unescape(document.getElementById("selProperty").options[i].value) + "&";
                }
            }
        }

        function SelectProperty() {
            var str = $("#selProperty").val().toString();
            str = unescape(str);
            $("#txtEditProperty").val(str.split('|')[0]);

        }

        function DeleteProperty() {
            var n = unescape(document.getElementById("selProperty").value).split('|')[2];
            if (isNull(n)) {
                alert("请选择要移除的属性！");
                return;
            }
            if (confirm("您确定要移除选中项吗?")) {
                $("#selProperty option:selected").remove();
                $("#txtEditProperty").val("");
                $("#txtEditPropertyValue").val("");
            }
        }

        function EditProperty() {
            var n = $.trim($("#txtEditProperty").val());

            if (isNull(n)) {
                alert("属性名不能为空！");
                $("#txtEditProperty").focus();
                return;
            }

            var id = unescape(document.getElementById("selProperty").value).split('|')[1];
            if ($('#selProperty option').length > 0) {
                for (var i = 0; i < $('#selProperty option').length; i++) {
                    if (unescape(document.getElementById("selProperty").options[i].value).split('|')[1] == id) {
                        document.getElementById("selProperty").options[i].value = n + "|" + id;
                        document.getElementById("selProperty").options[i].text = n;
                        break;
                    }
                }
            }
        }

    </script>
</head>
<body>
    <form id="form1" runat="server" method="post" onsubmit="return CheckInput();">
        <div>
            <f:PageManager ID="PageManager1" AutoSizePanelID="RegionPanel1" runat="server"></f:PageManager>
            <f:Form Width="600px" BodyPadding="5px" ID="Form2" LabelWidth="100px" EnableFrame="true" EnableCollapse="true"
                runat="server" Title="表单 1">
                <Rows>
                    <f:FormRow ColumnWidths="50% 50%">
                        <Items>
                            <f:TextBox ID="tbquestion" runat="server" Label="题目" Text=""></f:TextBox>

                        </Items>
                    </f:FormRow>
                    <f:FormRow ColumnWidths="50% 50%">
                        <Items>
                            <f:TextArea ID="taanswer" runat="server" Height="50px" Label="正确答案" Text=""></f:TextArea>

                        </Items>
                    </f:FormRow>
                    <f:FormRow ColumnWidths="50% 50%">
                        <Items>
                            <f:TextBox ID="tbpredifficult" runat="server" Label="预设难度" Text=""></f:TextBox>

                        </Items>
                    </f:FormRow>
                    <f:FormRow ColumnWidths="50% 50%">
                        <Items>
                            <f:TextBox ID="tbchapter" runat="server" Label="所属章" Text=""></f:TextBox>

                        </Items>
                    </f:FormRow>
                    <f:FormRow ColumnWidths="50% 50%">
                        <Items>
                            <f:TextBox ID="tbpart" runat="server" Label="所属节" Text=""></f:TextBox>

                        </Items>
                    </f:FormRow>
                    <f:FormRow ColumnWidths="50% 50%">
                        <Items>
                            <f:TextBox ID="tbblankline" runat="server" Label="空行" Text=""></f:TextBox>

                        </Items>
                    </f:FormRow>
                    <f:FormRow ColumnWidths="50% 50%">
                        <Items>
                            <f:TextBox ID="tbpartitiondegree" runat="server" Label="区分度" Text=""></f:TextBox>
                        </Items>
                    </f:FormRow>
                    <f:FormRow ColumnWidths="50% 50%">
                        <Items>
                            <table style="width: 90%; margin: 20px auto;">
                                <tr>
                                    <td colspan="5">选项：</td>
                                </tr>
                                <tr>
                                    <td>内容</td>
                                    <td>
                                        <input type="text" id="txtProperty" name="txtProperty" /></td>
                                    <td></td>
                                    <td></td>
                                    <td>
                                        <input type="button" id="Button1" name="btnAdd" value="添加" onclick="PropertyAdd();" /></td>
                                </tr>
                                <tr>
                                    <td colspan="4">
                                        <select id="selProperty" name="selProperty" multiple="multiple" style="width: 645px; height: 150px; margin-left: 168px;" onchange="SelectProperty();">
                                        </select>
                                        <input type="hidden" id="hidProperty" name="hidProperty" />
                                    </td>
                                    <td>
                                        <input type="button" id="btnUp" name="btnUp" value="上移" onclick="mUp('selProperty')" /><br />
                                        <br />
                                        <input type="button" id="btnDown" name="btnDown" value="下移" onclick="mDown('selProperty')" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>编辑项：</td>
                                    <td colspan="4">选项显示如下（可编辑移除）
                                    </td>
                                </tr>
                                <tr>
                                    <td>属性名：</td>
                                    <td>
                                        <input type="text" id="txtEditProperty" name="txtEditProperty" /></td>
                                    <td></td>
                                    <td></td>
                                    <td>
                                        <input type="button" id="btnEdit" name="btnEdit" value="编辑" onclick="EditProperty();" />&nbsp;<input type="button" id="btnDelete" name="btnDelete" value="移除" onclick="    DeleteProperty();" /></td>
                                </tr>
                            </table>

                        </Items>
                    </f:FormRow>
                    <f:FormRow>
                        <Items>
                            <f:Panel ID="Panel1" runat="server" ShowBorder="false"
                                ShowHeader="false">
                                <Items>
                                    <f:Button runat="server" Text="保存" CssClass="inline" ValidateForms="Form2"
                                        ID="btnSubmitForm1" OnClick="BtAdd_Click">
                                    </f:Button>

                                </Items>
                            </f:Panel>
                        </Items>
                    </f:FormRow>
                </Rows>
            </f:Form>
        </div>
    </form>
</body>
</html>
